<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业实现低成本数字化转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  0769-82282996  15899929162
// +----------------------------------------------------------------------
namespace app\controller\api\items\common;

use app\controller\api\Base;
use app\common\repositories\system\SystemPactRepository;
use app\common\repositories\items\ItemsBasicRepository;
use app\common\repositories\system\sms\SystemSmsConfigRepository;
class Config extends Base
{

    /**
     * 获取网站基本信息
     * @param ItemsBasicRepository $repository
     * @return mixed
     *
     * @author Amos
     * 2024-01-24 20:49
     */
    public function getItemsInfo(ItemsBasicRepository $repository)
    {
        $info = $repository->getConfig($this->request->propertyId);
        $data = [
            'name' => $info['name'] ?? '',
            'address' => $info['address'] ?? '',
            'wechat' => $info['wechat'] ?? '',
            'website' => $info['website'] ?? '',
            'support' => $info['support'] ?? '',
            'copyright' => $info['copyright'] ?? '',
            'wechat_code' => $info['wechat_code'] ?? '',
            'service_tel' => $info['service_tel'] ?? '',
            'expire_time' => $info['expire_time'] ?? '',
            'items_logo' => $info['items_logo'] ?? '',
            'items_icon' => $info['items_icon'] ?? ''
        ];
        return $this->success($data);
    }

    /**
     * 获取平台协议
     * @param SystemPactRepository $repository
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     *
     * @author Amos
     * 2024-01-24 20:45
     */
    public function getPactInfo(SystemPactRepository $repository)
    {
        $type = (int)$this->request->param('type');
        $pactInfo = $repository->getPactInfo($this->request->propertyId, $type);
        if (empty($pactInfo)) {
            return $this->error('协议不存在');
        }
        return $this->success($pactInfo['content'] ?? '');
    }

    /**
     * 获取短信配置
     * @param SystemSmsConfigRepository $repository
     * @return mixed
     *
     * @author Amos
     * 2024-01-24 20:44
     */
    public function getSmsConfig(SystemSmsConfigRepository $repository)
    {
        $config = $repository->getConfig($this->request->propertyId);
        $data = [
            'verify_img_code' => $config['verify_img_code'] ?? '',
            'send_sms_time_out' => $config['send_sms_time_out'] ?? ''
        ];
        return $this->success($data);
    }



}